<?php
/*
	招商中心
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';
if($_RQ['op']=='main'){
	$_SESSION['forward_url']='jy_ailiao/fuwu.index/';
	$return['setting']=$this->plugin_setting('page');
	set_html('title',$return['setting']['agent_center']?:'服务站中心');
	$fuwu=$this->get('fuwu',array('mid'=>$_SESSION['uid']));
	if($fuwu['status']!=1){
		$return['setting']['agent_title']=$return['setting']['agent_title']?:'服务站';
		exi('','error','jy_ailiao/fuwu.apply/');
	}
	$basic=model('core/member')->basic($_SESSION['uid']);
	$member=array_merge($fuwu,$basic);
	if($member['level_id']){
		$member['level']=$this->getcolumn('fuwu_level',array('id'=>$member['level_id']),'title');
	}else{
		$member['level']='普通等级';
	}
	$return['ordernum']=$this->count('commission',array('fuwuid'=>$fuwu['id']));
	$member['url']=custom_url('/member.index//fuwuid='.$fuwu['id'],true);
	$return['member']=$member;
	$data=array();
	//已结算佣金
	$data['balance_total']=$this->sum('balance',array('fuwuid'=>$fuwu['id']),'money');
	$data['balance_num']=$this->count('balance',array('fuwuid'=>$fuwu['id']));
	//待结算佣金
	$params=array('uniacid'=>$_SESSION['uniacid'],'fuwuid'=>$fuwu['id'],'status'=>1);
	/*if($this->setting['balance_day']){
		//结算天数
		$time=TIMESTAMP-intval($this->setting['balance_day'])*86400;
		$params['complete_time <']=$time;
	}*/
	$data['commission_1']=$this->sum('commission',$params,'money');
	$data['commission_total']=$this->sum('commission',array('uniacid'=>$_SESSION['uniacid'],'fuwuid'=>$fuwu['id']),'money');
	$data['agent_num'] = pdo_count('jy_ailiao_member',array('uniacid'=>$_SESSION['uniacid'],'fuwu_id'=>$fuwu['id']));
	$return['data']=$data;
	$mids=$this->getall('member',array('uniacid'=>$_SESSION['uniacid'],'fuwu_id'=>$fuwu['id']),'mid','mid');
	if($mids){
		$mids=array_keys($mids);
	}else{
		$mids=-1;
	}
	$status0 = pdo_count('jy_ailiao_pinglog',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$mids,'status'=>0));
	$status1 = pdo_count('jy_ailiao_pinglog',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$mids,'status'=>1));
	$status2 = pdo_count('jy_ailiao_pinglog',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$mids,'status'=>2));
	$status3 = pdo_count('jy_ailiao_pinglog',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$mids,'status'=>3));
	$return['statics']=array(
		'status0'=>$status0,
		'status1'=>$status1,
		'status2'=>$status2,
		'status3'=>$status3,
	);
	exi($return);
}
?>